package net.xuwu.marry.common.struts;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.xuwu.marry.common.constant.GlobinConstant;

import org.apache.struts2.StrutsStatics;
import org.apache.struts2.dispatcher.StrutsResultSupport;

import com.opensymphony.xwork2.ActionInvocation;

	/**
	 * struts2 �ָ�����  ����json���
	 * @author Administrator
	 *
	 */
public class MarryStringResult extends StrutsResultSupport{

	
	private static final long serialVersionUID = 1516732216616353678L;

	private String contentTypeName;
	
	private String stringName;
	
	public MarryStringResult() {
		super();
	}

	@Override
	protected void doExecute(String arg0, ActionInvocation invocation)
			throws Exception {
		
		HttpServletResponse response = (HttpServletResponse) invocation.getInvocationContext().get(StrutsStatics.HTTP_RESPONSE);
		HttpServletRequest request = (HttpServletRequest) invocation.getInvocationContext().get(StrutsStatics.HTTP_REQUEST);
		
		String contentType = conditionalParse(contentTypeName, invocation);
		if(contentType==null){
			contentType = "text/plain; charset=UTF-8";
		}
		
		response.setContentType(contentType);
		String result = (String) invocation.getStack().findValue(stringName);
		request.setAttribute(GlobinConstant.SEND_JSON_DATA, result);
	}

	public String getContentTypeName() {
		return contentTypeName;
	}

	public void setContentTypeName(String contentTypeName) {
		this.contentTypeName = contentTypeName;
	}

	public String getStringName() {
		return stringName;
	}

	public void setStringName(String stringName) {
		this.stringName = stringName;
	}

	
}
